package com.example.administrator.smartdevice.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;

import com.example.administrator.smartdevice.R;
import com.example.administrator.smartdevice.base.BaseActivity;
import com.example.administrator.smartdevice.event.MessageEvent;
import com.example.administrator.smartdevice.fragment.AuthorizedFragment;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class PermissionManageActivity extends BaseActivity {
    @BindView(R.id.activity_permission_manage_viewpager)
    protected ViewPager activity_permission_manage_viewpager;

    @BindView(R.id.activity_permission_manage_list_tab)
    protected TabLayout activity_permission_manage_list_tab;

    private FragmentPagerAdapter fragmentPagerAdapter;
    private List<Fragment> fragmentList;
    private AuthorizedFragment authorizedFragment;
    private AuthorizedFragment unAuthorizedFragment;

    private List<String> titleList;
    private int state = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_permission_manage);
    }

    @Override
    protected void initData() {
        initCommonHeader();
        initFragmentList();
        initViewPager();
    }

    @Override
    protected void onFailure(int requestCode, Object object) {

    }

    @Override
    protected void onSuccess(int requestCode, Object object) {

    }

    protected void initCommonHeader() {
        configCommonHeader(this, "权限管理", false);
    }


    protected void initFragmentList() {
        authorizedFragment = new AuthorizedFragment();
        Bundle bundle = new Bundle();
        bundle.putString("messageStatus", "0");
        authorizedFragment.setArguments(bundle);

        unAuthorizedFragment = new AuthorizedFragment();
        Bundle bundle1 = new Bundle();
        bundle1.putString("messageStatus", "1");
        unAuthorizedFragment.setArguments(bundle1);

        fragmentList = new ArrayList<>();
        fragmentList.add(authorizedFragment);
        fragmentList.add(unAuthorizedFragment);

        titleList = new ArrayList<>();
        titleList.add("未授权");
        titleList.add("已授权");
    }

    protected void initViewPager() {
        fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public Fragment getItem(int arg0) {
                return fragmentList.get(arg0);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titleList.get(position);
            }
        };

        activity_permission_manage_viewpager.setAdapter(fragmentPagerAdapter);
        activity_permission_manage_viewpager.setOffscreenPageLimit(2);
        activity_permission_manage_viewpager.setCurrentItem(state);
        activity_permission_manage_list_tab.setupWithViewPager(activity_permission_manage_viewpager);
    }
}
